package com.example.hengjun.operation_oracle.advance;

import java.util.HashMap;
import java.util.Map;

class Solution {
    public static int lengthOfLongestSubstring(String s) {
        int i = 0, j  = 0, mm = 0;
        int len = s.length();
        Map<Character,Integer> map = new HashMap<Character, Integer>();

        for (j = 0; j < len; j++) {
            if (!map.containsKey(s.charAt(j))) {
                map.put(s.charAt(j), 1);
                mm = Math.max(mm, j - i + 1);
            }else {
                while (s.charAt(i) != s.charAt(j)) {
                    map.remove(s.charAt(i));
                    i++;
                }
                i++;
            }
        }
        return mm;
    }

    public static void main(String[] args) {
        String s = "tmmzuxt";
        System.out.println(lengthOfLongestSubstring(s) + " ");

    }
}